/**
 * 
 */
package com.dp.behav.interpreter;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * This is to describe interpreter pattern.
 * 
 * The Interpreter Pattern defines a grammatical representation for a language
 * and an interpreter to interpret the grammar.Its intent is to define a
 * representation for its grammar along with an interpreter that uses the
 * representation to interpret sentences into a language.
 * 
 * @author Sunaina.Sharma
 * 
 */
public class Interpreter {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String roman = "MCMXXVIII";
		Context context = new Context(roman);

		// Build the 'parse tree'
		ArrayList<Expression> tree = new ArrayList<Expression>();
		tree.add(new ThousandExpression());
		tree.add(new HundredExpression());
		tree.add(new TenExpression());
		tree.add(new OneExpression());

		// Interpret
		for (Iterator<Expression> it = tree.iterator(); it.hasNext();) {
			Expression exp = (Expression) it.next();
			exp.interpret(context);
		}

		System.out.println(roman + " = "
				+ Integer.toString(context.getOutput()));
	}

}
